<?php
namespace app\client\controller;
use think\Controller;
class Base extends Controller{
    protected $userid = 0;
    public function __construct(){
        parent::__construct();
        $token = request()->header('token');
        
        if($token){
            $signer = new \Lcobucci\JWT\Signer\Hmac\Sha256();
            $token = (new \Lcobucci\JWT\Parser())->parse($token);
            $res = $token->verify($signer,config('config.jwtKey'));;
            if(!$res){
                return;
            }
            $userid = $token->getClaim('key', false);
            $this->userid = base64_decode($userid) / 1030;
            $user = model('User')->findOne(['user_id' => $this->userid], 'mobile, openid');
            if(empty($user)){
                return;
            }
            
            session('user', $user);
        }else {
        }
        
    }
    
    public function noLogin() {
        return $this->userid == 0;
    }
    
    public function noLoginReturn() {
        return errorResult('未登陆', 301);
    }

}





